﻿/**  版本信息模板在安装目录下，可自行修改。
* StaffTestQueLog.cs
*
* 功 能： N/A
* 类 名： StaffTestQueLog
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2015/5/17 12:39:40   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Catering_DBOpertion;
namespace Catering_Operation
{
	/// <summary>
	/// 数据访问类:StaffTestQueLog
	/// </summary>
	public partial class StaffTestQueLog
	{
		public StaffTestQueLog()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("TestID", "T_StaffTestQueLog"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int TestID,int UserID,int QueID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_StaffTestQueLog");
			strSql.Append(" where TestID=@TestID and UserID=@UserID and QueID=@QueID ");
			SqlParameter[] parameters = {
					new SqlParameter("@TestID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@QueID", SqlDbType.Int,4)			};
			parameters[0].Value = TestID;
			parameters[1].Value = UserID;
			parameters[2].Value = QueID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Catering_Model.StaffTestQueLog model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_StaffTestQueLog(");
			strSql.Append("TestID,UserID,QueID,TestName,QueNO,QueName,QueAnswer,UserAnswer,QueType,QueContentA,QueContentB,QueContentC,QueContentD,QuePoints,UserPoints,AddTime)");
			strSql.Append(" values (");
			strSql.Append("@TestID,@UserID,@QueID,@TestName,@QueNO,@QueName,@QueAnswer,@UserAnswer,@QueType,@QueContentA,@QueContentB,@QueContentC,@QueContentD,@QuePoints,@UserPoints,@AddTime)");
			SqlParameter[] parameters = {
					new SqlParameter("@TestID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@QueID", SqlDbType.Int,4),
					new SqlParameter("@TestName", SqlDbType.VarChar,1000),
					new SqlParameter("@QueNO", SqlDbType.VarChar,50),
					new SqlParameter("@QueName", SqlDbType.VarChar,100),
					new SqlParameter("@QueAnswer", SqlDbType.VarChar,50),
					new SqlParameter("@UserAnswer", SqlDbType.VarChar,50),
					new SqlParameter("@QueType", SqlDbType.VarChar,4),
					new SqlParameter("@QueContentA", SqlDbType.Text),
					new SqlParameter("@QueContentB", SqlDbType.Text),
					new SqlParameter("@QueContentC", SqlDbType.Text),
					new SqlParameter("@QueContentD", SqlDbType.Text),
					new SqlParameter("@QuePoints", SqlDbType.Decimal,5),
					new SqlParameter("@UserPoints", SqlDbType.Decimal,5),
					new SqlParameter("@AddTime", SqlDbType.DateTime)};
			parameters[0].Value = model.TestID;
			parameters[1].Value = model.UserID;
			parameters[2].Value = model.QueID;
			parameters[3].Value = model.TestName;
			parameters[4].Value = model.QueNO;
			parameters[5].Value = model.QueName;
			parameters[6].Value = model.QueAnswer;
			parameters[7].Value = model.UserAnswer;
			parameters[8].Value = model.QueType;
			parameters[9].Value = model.QueContentA;
			parameters[10].Value = model.QueContentB;
			parameters[11].Value = model.QueContentC;
			parameters[12].Value = model.QueContentD;
			parameters[13].Value = model.QuePoints;
			parameters[14].Value = model.UserPoints;
			parameters[15].Value = model.AddTime;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Catering_Model.StaffTestQueLog model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_StaffTestQueLog set ");
			strSql.Append("TestName=@TestName,");
			strSql.Append("QueNO=@QueNO,");
			strSql.Append("QueName=@QueName,");
			strSql.Append("QueAnswer=@QueAnswer,");
			strSql.Append("UserAnswer=@UserAnswer,");
			strSql.Append("QueType=@QueType,");
			strSql.Append("QueContentA=@QueContentA,");
			strSql.Append("QueContentB=@QueContentB,");
			strSql.Append("QueContentC=@QueContentC,");
			strSql.Append("QueContentD=@QueContentD,");
			strSql.Append("QuePoints=@QuePoints,");
			strSql.Append("UserPoints=@UserPoints,");
			strSql.Append("AddTime=@AddTime");
			strSql.Append(" where TestID=@TestID and UserID=@UserID and QueID=@QueID ");
			SqlParameter[] parameters = {
					new SqlParameter("@TestName", SqlDbType.VarChar,1000),
					new SqlParameter("@QueNO", SqlDbType.VarChar,50),
					new SqlParameter("@QueName", SqlDbType.VarChar,100),
					new SqlParameter("@QueAnswer", SqlDbType.VarChar,50),
					new SqlParameter("@UserAnswer", SqlDbType.VarChar,50),
					new SqlParameter("@QueType", SqlDbType.VarChar,4),
					new SqlParameter("@QueContentA", SqlDbType.Text),
					new SqlParameter("@QueContentB", SqlDbType.Text),
					new SqlParameter("@QueContentC", SqlDbType.Text),
					new SqlParameter("@QueContentD", SqlDbType.Text),
					new SqlParameter("@QuePoints", SqlDbType.Decimal,5),
					new SqlParameter("@UserPoints", SqlDbType.Decimal,5),
					new SqlParameter("@AddTime", SqlDbType.DateTime),
					new SqlParameter("@TestID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@QueID", SqlDbType.Int,4)};
			parameters[0].Value = model.TestName;
			parameters[1].Value = model.QueNO;
			parameters[2].Value = model.QueName;
			parameters[3].Value = model.QueAnswer;
			parameters[4].Value = model.UserAnswer;
			parameters[5].Value = model.QueType;
			parameters[6].Value = model.QueContentA;
			parameters[7].Value = model.QueContentB;
			parameters[8].Value = model.QueContentC;
			parameters[9].Value = model.QueContentD;
			parameters[10].Value = model.QuePoints;
			parameters[11].Value = model.UserPoints;
			parameters[12].Value = model.AddTime;
			parameters[13].Value = model.TestID;
			parameters[14].Value = model.UserID;
			parameters[15].Value = model.QueID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int TestID,int UserID,int QueID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_StaffTestQueLog ");
			strSql.Append(" where TestID=@TestID and UserID=@UserID and QueID=@QueID ");
			SqlParameter[] parameters = {
					new SqlParameter("@TestID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@QueID", SqlDbType.Int,4)			};
			parameters[0].Value = TestID;
			parameters[1].Value = UserID;
			parameters[2].Value = QueID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Catering_Model.StaffTestQueLog GetModel(int TestID,int UserID,int QueID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 TestID,UserID,QueID,TestName,QueNO,QueName,QueAnswer,UserAnswer,QueType,QueContentA,QueContentB,QueContentC,QueContentD,QuePoints,UserPoints,AddTime from T_StaffTestQueLog ");
			strSql.Append(" where TestID=@TestID and UserID=@UserID and QueID=@QueID ");
			SqlParameter[] parameters = {
					new SqlParameter("@TestID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@QueID", SqlDbType.Int,4)			};
			parameters[0].Value = TestID;
			parameters[1].Value = UserID;
			parameters[2].Value = QueID;

			Catering_Model.StaffTestQueLog model=new Catering_Model.StaffTestQueLog();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Catering_Model.StaffTestQueLog DataRowToModel(DataRow row)
		{
			Catering_Model.StaffTestQueLog model=new Catering_Model.StaffTestQueLog();
			if (row != null)
			{
				if(row["TestID"]!=null && row["TestID"].ToString()!="")
				{
					model.TestID=int.Parse(row["TestID"].ToString());
				}
				if(row["UserID"]!=null && row["UserID"].ToString()!="")
				{
					model.UserID=int.Parse(row["UserID"].ToString());
				}
				if(row["QueID"]!=null && row["QueID"].ToString()!="")
				{
					model.QueID=int.Parse(row["QueID"].ToString());
				}
				if(row["TestName"]!=null)
				{
					model.TestName=row["TestName"].ToString();
				}
				if(row["QueNO"]!=null)
				{
					model.QueNO=row["QueNO"].ToString();
				}
				if(row["QueName"]!=null)
				{
					model.QueName=row["QueName"].ToString();
				}
				if(row["QueAnswer"]!=null)
				{
					model.QueAnswer=row["QueAnswer"].ToString();
				}
				if(row["UserAnswer"]!=null)
				{
					model.UserAnswer=row["UserAnswer"].ToString();
				}
				if(row["QueType"]!=null)
				{
					model.QueType=row["QueType"].ToString();
				}
				if(row["QueContentA"]!=null)
				{
					model.QueContentA=row["QueContentA"].ToString();
				}
				if(row["QueContentB"]!=null)
				{
					model.QueContentB=row["QueContentB"].ToString();
				}
				if(row["QueContentC"]!=null)
				{
					model.QueContentC=row["QueContentC"].ToString();
				}
				if(row["QueContentD"]!=null)
				{
					model.QueContentD=row["QueContentD"].ToString();
				}
				if(row["QuePoints"]!=null && row["QuePoints"].ToString()!="")
				{
					model.QuePoints=decimal.Parse(row["QuePoints"].ToString());
				}
				if(row["UserPoints"]!=null && row["UserPoints"].ToString()!="")
				{
					model.UserPoints=decimal.Parse(row["UserPoints"].ToString());
				}
				if(row["AddTime"]!=null && row["AddTime"].ToString()!="")
				{
					model.AddTime=DateTime.Parse(row["AddTime"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select TestID,UserID,QueID,TestName,QueNO,QueName,QueAnswer,UserAnswer,QueType,QueContentA,QueContentB,QueContentC,QueContentD,QuePoints,UserPoints,AddTime ");
			strSql.Append(" FROM T_StaffTestQueLog ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" TestID,UserID,QueID,TestName,QueNO,QueName,QueAnswer,UserAnswer,QueType,QueContentA,QueContentB,QueContentC,QueContentD,QuePoints,UserPoints,AddTime ");
			strSql.Append(" FROM T_StaffTestQueLog ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_StaffTestQueLog ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.QueID desc");
			}
			strSql.Append(")AS Row, T.*  from T_StaffTestQueLog T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_StaffTestQueLog";
			parameters[1].Value = "QueID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

